﻿<UserControl x:Class="CertificatesGrid"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ProgettoSicurezza.CertificationAuthority"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Status}" Value="Current">
                    <Setter Property="Background" Value="PaleGreen" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Expired">
                    <Setter Property="Background" Value="SandyBrown" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Revoked">
                    <Setter Property="Background" Value="Tomato" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>


        <DataGrid Name="dg" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" VerticalScrollBarVisibility="Auto">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="User Name" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Username}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Serial n°" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ID}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Valid from" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Certificate.NotBefore}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Valid until" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Certificate.NotAfter}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Type" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CertificateType}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Status" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Status}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="Details" IsReadOnly="True" Width="*">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2">
                                <Button Content="Show details" Margin="2" Click="ButtonOldCertDetails_Click"/>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

            </DataGrid.Columns>
        </DataGrid>
        <!--</ScrollViewer>-->

        <GroupBox Header="Filter" Grid.Row="1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="Only show certificates that are:" Margin="3" HorizontalAlignment="Center"/>
                <Label Background="PaleGreen" Grid.Column="1" HorizontalContentAlignment="Center">
                    <CheckBox Content="Current" Click="FilterChanged" Name="cbCurrent" IsChecked="True" IsThreeState="False" />
                </Label>
                <Label Background="SandyBrown" Grid.Column="2" HorizontalContentAlignment="Center">
                    <CheckBox Content="Expired" Click="FilterChanged" Name="cbExpired" IsChecked="True" IsThreeState="False"/>
                </Label>
                <Label Background="Tomato" Grid.Column="3" HorizontalContentAlignment="Center">
                    <CheckBox Content="Revoked" Click="FilterChanged" Name="cbRevoked" IsChecked="True" IsThreeState="False"/>
                </Label>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
